package com.wanxi.app.service.user;

import com.wanxi.login.api.LoginFeign;
import com.wanxi.login.domain.result.LoginResult;
import com.wanxi.user.api.UserFeign;
import com.wanxi.user.domain.dto.UserInfoDto;
import com.wanxi.user.domain.entity.UserInfo;
import com.wanxi.user.domain.result.UserResult;
import org.springframework.stereotype.Service;


import javax.annotation.Resource;

/**
 * @Author:wgy
 * @Data：2022/1/13 17:14
 */
@Service
public class UserService {

    @Resource
    private UserFeign userFeign;

    @Resource
    private LoginFeign loginFeign;

    /**
     *
     * @param userId 用户id
     * @return
     */
    public UserResult<UserInfo> findById(long userId) {
        UserResult<UserInfo> byId = userFeign.findById(userId);
        if (byId.getData() != null) {
            return byId;
        }
        return UserResult.failed();
    }

    public UserResult<Boolean> updateById(UserInfoDto userInfoDto) {
//        LoginResult<Long> roleIdById = loginFeign.findRoleIdById(userInfoDto.getId());
//        userInfoDto.setId(roleIdById.getData());
        UserResult<Boolean> userResult = userFeign.updateById(userInfoDto);
        if (userResult.getData()) {
            return userResult;
        }
        return UserResult.failed();
    }


    public UserResult<Boolean> delById(UserInfoDto userInfoDto) {

        UserResult<Boolean> userResult = userFeign.updateById(userInfoDto);
        if (userResult.getData()) {
            return userResult;
        }
        return UserResult.failed();
    }


}